草庐IT

Matplotlib 散点图

全部标签

python - 在 python (Matplotlib) 中使用子图和 imshow 时删除白色边框

importnumpyasnpimportsysimportmatplotlibasmplimportmatplotlib.pyplotasplt我使用下面的代码来保存一张图片fig,ax=plt.subplots(frameon=False)ax.axis('off')ax.imshow(array[:,:,0,0,0])fig.savefig("file.png",bbox_inches='tight')然而,我得到的是这显然还有一个白色的边框。我该如何摆脱它?array.shape是:(256,256,1,1,3) 最佳答案

python - python的matplotlib中如何获取当前图号?

我正在研究一个示例脚本,该脚本展示了如何在图形之间来回切换。我在这里找到了这个例子:http://matplotlib.org/examples/pylab_examples/multiple_figs_demo.html当我尝试打印数字时,我得到的是“Figure(640x480)”而不是我期望的数字1。你是怎么得到这个号码的?#Workingwithmultiplefigurewindowsandsubplotsimportmatplotlib.pyplotaspltimportnumpyasnpt=np.arange(0.0,2.0,0.01)s1=np.sin(2*np.pi*

python - 使用带有LinkedBrush的matplotlib mpld3的Json序列化错误

LinkedBrush的mpld3(d3上的matplotlib)示例http://mpld3.github.io/examples/linked_brush.html提供以下代码示例:importnumpyasnpimportmatplotlibimportmatplotlib.pyplotaspltfromsklearn.datasetsimportload_irisimportmpld3frommpld3importplugins,utilsdata=load_iris()X=data.datay=data.target#ditherthedataforclearerplotti

python - 如何防止使用 matplotlib 对 python 条进行字母排序?

我正在使用条形图绘制一些分类数据。即使我对数据框值进行排序,Matplotlib仍会按字母顺序对x轴进行排序。这是我的代码:fig3,new_ax=plt.subplots(1,1,figsize=(25/3,5))summary=tsa.source.sum().sort_values(ascending=False)new_ax.bar(summary.index,summary.values,color=my_colors)new_ax.legend()bar_heights(new_ax)#customfunctiontogetthevaluesontopofbarssimpl

python - IOError : "decoder zip not available" using matplotlib PNG in ReportLab on Linux, 适用于 Windows

我正在使用ReportLab打印由matplotlib生成的图表。我可以在我的Windows开发机器上毫无问题地执行此操作。但是,当我部署到Ubuntu服务器时,渲染失败并出现所述错误。我假设我缺少一个Python模块,但我不知道是哪一个。我相信Python、matplotlib、ReportLab和PIL的版本在我的开发机器和服务器上都是相同的。将matplotlib图(称为图表)转换为PNG并返回的代码:img_stream=StringIO.StringIO()chart.savefig(img_stream,format='png')img_stream.seek(0)retu

python - matplotlib:使用颜色图为表格单元格背景着色

我有一个Pandas数据框,我想将其绘制为matplotlib表。到目前为止,我已经使用了以下代码:importnumpyasnprandn=np.random.randnfrompandasimport*idx=Index(arange(1,11))df=DataFrame(randn(10,5),index=idx,columns=['A','B','C','D','E'])vals=np.around(df.values,2)fig=plt.figure(figsize=(15,8))ax=fig.add_subplot(111,frameon=True,xticks=[],yt

python - 如何更改 networkx/matplotlib 图形绘图的属性?

NetworkX包括functions使用matplotlib绘制图形.这是一个使用出色的IPythonNotebook的示例(从ipython3notebook--pylabinline开始):很好,作为一个开始。但是我怎样才能影响绘图的属性,比如着色、线宽和标签?我以前没有使用过matplotlib。 最佳答案 IPython是找出函数(和对象)可以做什么的好工具。如果你输入[1]:importnetworkxasnx[2]:nx.draw?你看Definition:nx.draw(G,pos=None,ax=None,hold

python - 如何获取 Matplotlib 生成的散点图的像素坐标?

我使用Matplotlib生成散点图的PNG文件。现在,对于每个散点图,除了PNG文件之外,我还想生成散点图中各个点的像素坐标列表。我用来为散点图生成PNG文件的代码基本上是这样的:frommatplotlib.figureimportFigurefrommatplotlib.pyplotimportsetpfrommatplotlib.backends.backend_aggimportFigureCanvasAgg...fig=Figure(figsize=(3,3),dpi=100)ax=fig.gca()for(x,y),m,cinzip(points,markers,colo

python - Python 中数组的 2D 和 3D 散点直方图

你知道我如何将3个数组合并为直方图吗?我的阵列看起来像Temperature=[4,3,1,4,6,7,8,3,1]Radius=[0,2,3,4,0,1,2,10,7]Density=[1,10,2,24,7,10,21,102,203]一维图应该是这样的:Density|X10^2-|X|X10^1-||X10^0-||___|___|___|___|___Radius03.36.610二维图应该(定性)如下所示:Density|2||10^2-|11249|||233||Radius10^1-|12|||1||10^0-||___|___|___|___|___Temperatu

python - matplotlib 强制平移/缩放限制到 x 轴

Matplotlib有一个功能,如果您按住“x”或“y”键,它会限制平移或缩放到相应的轴。有没有办法让它成为默认值?出于某种原因,我的CPU不允许在按住字母键时触摸板移动。我只希望平移/缩放x轴,而不是y轴。编辑:在https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes.py#L3001找到平移/缩放功能其中包含一个内部函数format_deltas。但是当Axes对象是从Figure对象自动创建时,我不知道如何用子类覆盖Axes类。 最佳答案